﻿using System;
using System.Collections.Generic;
using System.Text;

namespace osuStd2Key
{
    public class KeyNote
    {
        public class Vector2
        {
            public int x;
            public int y;
            public Vector2(int _x, int _y)
            {
                x = _x;
                y = _y;
            }
            public void ToNotePos(Note n) {
                n.x = x;
                n.y = y;
            }
            public override int GetHashCode()
            {
                return x * 1000 + Math.Abs(y);
            }
            public override bool Equals(object o)
            {
                if (o == null) return false;
                if (o.GetType() != typeof(Vector2)) return false;
                var n = (Vector2)o;
                return n.x == x && n.y == y;
            }
        }
        public List<Note> Notes = new List<Note>();
        public enum NoteType
        {
            Unknown = 0,
            Normal = 1,
            Normal_WAY = 2,
            Normal_LONG = 3,
            DOUBLE = 4,
            DOUBLE_WAY = 5,
            DOUBLE_LONG = 6,
            HEART = 7,
            SHOW_TIME = 11
        }
        public enum WayDirection
        {
            Up = 0,
            UpRight = 45,
            Right = 90,
            DownRight = 135,
            Down = 180,
            DownLeft = 225,
            Left = 270,
            UpLeft = 315,
            unknown = -1
        }
        public class Note
        {
            public int ishide = 0;
            public int showFrame = 4;
            public int offsetFrame = 0;
            public int frame = 0;
            public NoteType type = NoteType.Normal;
            public WayDirection wayAngle = WayDirection.Up; //WayDirection.Up is 0
            public int bpm4X4 = 1;
            public int x;
            public int y;
            public int x1 = 0;
            public int y1 = 0;
            public string info
            {
                get
                {
                    switch (type)
                    {
                        case NoteType.Normal: return "单键";
                        case NoteType.Normal_WAY: return "单键方向";
                        case NoteType.Normal_LONG: return "单键长按";
                        case NoteType.DOUBLE: return "双键";
                        case NoteType.DOUBLE_WAY: return "双键方向";
                        case NoteType.DOUBLE_LONG: return "双键长按";
                        case NoteType.HEART: return "气球";
                        case NoteType.SHOW_TIME: return "SHOWTIME";
                        default: return "";
                    }
                }
            }
            public int id
            {
                get { return (int)type; }
            }
            public string name
            {
                get { return type.ToString(); }
            }
            public override string ToString()
            {
                return string.Format("<data ishide=\"{0}\" showFrame=\"{1}\" offsetFrame=\"{2}\" frame=\"{3}\" type=\"{4}\" info=\"{5}\" name=\"{6}\" id=\"{7}\" wayAngle=\"{8}\" bpm4X4=\"{9}\" x=\"{10}\" y=\"{11}\" x1=\"{12}\" y1=\"{13}\"/>",
                    ishide,
                    showFrame,
                    offsetFrame,
                    frame,
                    (int)type,
                    info,
                    name,
                    id,
                    (int)wayAngle,
                    bpm4X4,
                    x,
                    y,
                    x1,
                    y1
                    );
            }
        }
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<keys>\r\n");
            foreach (Note n in Notes)
            {
                sb.Append(n.ToString());
                sb.Append("\r\n");
            }
            sb.Append("</keys>\r\n");
            return sb.ToString();
        }
    }
}
